package cn.itcast.mq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {

    /**
     * 创建一个广播交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange1(){

        return new FanoutExchange("sysion.fanout");
    }

    /**
     * 创建第一个队列
     * @return
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("sysion1.queue1");
    }

    /**
     * 绑定广播交换机和队列
     * @param fanoutExchange1
     * @param fanoutQueue1
     * @return
     */
    @Bean
    public Binding  bindingQueue1(FanoutExchange fanoutExchange1,Queue fanoutQueue1){

        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange1);
    }

    /**
     * 创建第二个队列
     * @return
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("sysion2.queue2");
    }

    /**
     * 第二次绑定广播交换机和队列
     * @param fanoutExchange1
     * @param fanoutQueue2
     * @return
     */
    @Bean
    public Binding  bindingQueue2(FanoutExchange fanoutExchange1,Queue fanoutQueue2){

        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange1);
    }

}
